'use strict';
const base = require('./base');

module.exports = app => {
    const { STRING, INTEGER, DECIMAL } = app.Sequelize;

    const Book = app.model.define('book',
        Object.assign(base(app), {
            // id: { type: INTEGER, primaryKey: true, autoIncrement: true },
            book_num: {type:STRING(64), primaryKey: true},
            book_name: STRING(64),
            writer: STRING(32),
            publisher: STRING(255),
            introduction: STRING(255),
            // borrow_id: { type: INTEGER(11), defaultValue: () => 0 },
            // state: { type: INTEGER(11), defaultValue: () => 0 },
            amount: INTEGER,
            price: DECIMAL(10),
            site: STRING(32),
        }));
    Book.associate = () => {
        Book.belongsToMany(app.model.Sys.User, {
            foreignKey: 'book_num',
            through:app.model.Borrow,
            sourceKey:'book_num'
        });
        Book.hasMany(app.model.Borrow, {
            foreignKey: 'book_num',
        });
    };
    return Book;
};
